<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>日志上传测试</title>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            line-height: 1.6;
        }
        h1 {
            color: #333;
            border-bottom: 2px solid #42b983;
            padding-bottom: 10px;
        }
        .container {
            background: #f5f5f5;
            padding: 20px;
            border-radius: 8px;
            margin-bottom: 20px;
        }
        button {
            background-color: #42b983;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        button:hover {
            background-color: #35495e;
        }
        #result {
            margin-top: 20px;
            padding: 15px;
            background: white;
            border-radius: 4px;
            border: 1px solid #ddd;
            white-space: pre-wrap;
            max-height: 300px;
            overflow-y: auto;
        }
        .success {
            color: #42b983;
        }
        .error {
            color: #ff4d4f;
        }
        .info {
            color: #1890ff;
        }
    </style>
</head>
<body>
    <h1>日志上传功能测试</h1>
    
    <div class="container">
        <p>此页面用于测试前端日志上传功能是否正常工作。点击下方按钮开始测试：</p>
        <button id="testUploadBtn">测试日志上传</button>
        <button id="addLogBtn">添加测试日志</button>
    </div>
    
    <div id="result">
        <p class="info">测试结果将显示在这里...</p>
    </div>
    
    <script>
        // 等待页面加载完成
        window.addEventListener('load', function() {
            const testUploadBtn = document.getElementById('testUploadBtn');
            const addLogBtn = document.getElementById('addLogBtn');
            const resultElem = document.getElementById('result');
            
            // 检查Logger是否可用
            if (window.Logger) {
                resultElem.innerHTML = '<p class="info">Logger对象已加载，准备测试...</p>';
            } else {
                resultElem.innerHTML = '<p class="error">⚠️ Logger对象不可用，请先加载Logger.js</p>';
                testUploadBtn.disabled = true;
                addLogBtn.disabled = true;
                return;
            }
            
            // 添加测试日志
            addLogBtn.addEventListener('click', function() {
                const timestamp = new Date().toLocaleString();
                const logMessage = `测试日志消息 - ${timestamp} - ${Math.random().toString(36).substr(2, 5)}`;
                
                // 记录不同级别的日志
                Logger.info('INFO: ' + logMessage);
                Logger.warn('WARN: ' + logMessage);
                Logger.error('ERROR: ' + logMessage);
                
                resultElem.innerHTML += `<p class="info">已添加测试日志：${logMessage}</p>`;
            });
            
            // 测试日志上传
            testUploadBtn.addEventListener('click', async function() {
                resultElem.innerHTML = '<p class="info">正在尝试上传日志，请稍候...</p>';
                
                try {
                    // 检查是否启用了日志上传
                    console.log('Logger配置:', {
                        uploadEnabled: window.Logger.modules.app.uploadEnabled,
                        uploadUrl: window.Logger.modules.app.uploadUrl
                    });
                    
                    // 直接调用Logger的uploadLogs方法
                    if (typeof window.Logger.uploadLogs === 'function') {
                        await window.Logger.uploadLogs();
                        resultElem.innerHTML += '<p class="success">✅ 日志上传调用成功！</p>';
                        resultElem.innerHTML += '<p class="info">请检查浏览器控制台和后端日志文件查看详细信息。</p>';
                    } else if (window.Logger.modules && window.Logger.modules.app && typeof window.Logger.modules.app.uploadLogs === 'function') {
                        await window.Logger.modules.app.uploadLogs();
                        resultElem.innerHTML += '<p class="success">✅ 日志上传调用成功！</p>';
                        resultElem.innerHTML += '<p class="info">请检查浏览器控制台和后端日志文件查看详细信息。</p>';
                    } else {
                        resultElem.innerHTML += '<p class="error">❌ uploadLogs方法不可用</p>';
                    }
                } catch (error) {
                    resultElem.innerHTML += `<p class="error">❌ 上传失败: ${error.message}</p>`;
                    resultElem.innerHTML += `<p class="error">错误详情: ${error.stack}</p>`;
                    console.error('日志上传错误:', error);
                }
            });
            
            // 检查是否有token
            const token = localStorage.getItem('token');
            if (!token) {
                resultElem.innerHTML += '<p class="error">⚠️ 未检测到登录token，可能会导致401/403错误</p>';
            }
        });
    </script>
</body>
</html>